package com.kucai.yifaqapp.presenter.fragment;

import android.util.Log;
import android.widget.Toast;

import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.Res11xuan5;
import com.kucai.yifaqapp.model.network.entity.res.ResGameDetails;
import com.kucai.yifaqapp.model.network.entity.res.ResMoney;
import com.kucai.yifaqapp.model.network.entity.res.ResSetbet;
import com.kucai.yifaqapp.model.network.entity.res.Reskuaile10fen;
import com.kucai.yifaqapp.model.network.entity.res.Resxingyunnongchang;
import com.kucai.yifaqapp.ui.fragment.gameFragment.NCragment;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/10.
 */

public class NCragmentPresenter extends BaseFragmentPresenter<NCragment> {


    public NCragmentPresenter(NCragment mFragment) {
        super(mFragment);
    }


    //广东十分
    public void getkuaileshifenddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getkuaileshifenddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds",gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Reskuaile10fen>(mFragment) {
                    @Override
                    protected void onCustomNext(Reskuaile10fen resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setkuaileshifen(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //广东十分
    public void getxingyunnongchangddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getxingyunnongchangddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds",gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resxingyunnongchang>() {
                    @Override
                    protected void onCustomNext(Resxingyunnongchang resOods) {

                        if (resOods.code.equals("0")) {
                            mFragment.setxingyunnongchangddes(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //十一选五
    public void getshiyixuanwuddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getshiyixuanwuddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds",gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Res11xuan5>(mFragment) {
                    @Override
                    protected void onCustomNext(Res11xuan5 resOods) {

                        if (resOods.code.equals("0")) {
                            mFragment.setshiyixuanwuddes(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取游戏详情
    public void getgamesdetail(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do",gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if (("广东11选5").equals(resGameDetails.data.game_name)) {
                                mFragment.shiyixuanwu(resGameDetails);
                            } else if (("广东快乐十分").equals(resGameDetails.data.game_name) || ("重庆幸运农场").equals(resGameDetails.data.game_name)) {
                                mFragment.guangdongkuaileshifen(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }
//获取游戏详情
    public void getgamesdetail1(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do",gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if (("广东11选5").equals(resGameDetails.data.game_name)) {
                                mFragment.shiyixuanwu1(resGameDetails);
                            } else if (("广东快乐十分").equals(resGameDetails.data.game_name) || ("重庆幸运农场").equals(resGameDetails.data.game_name)) {
                                mFragment.guangdongkuaileshifen1(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //下注
    public void Betbet(final String data, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .Betbet(HttpAdress.getuseAdress() + "api/m/lottery/bet.do",data, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResSetbet>(mFragment) {
                    @Override
                    protected void onCustomNext(ResSetbet resOods) {

                        if ("200".equals(resOods.code)) {
                            mFragment.betsuccses();
                        } else {
                            Toast.makeText(mFragment.getContext(), resOods.msg, Toast.LENGTH_SHORT).show();
                            mFragment.betfail();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取余额
    public void getmoney(String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getmoney(HttpAdress.getuseAdress() + "api/m/user/getMoney",token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResMoney>() {
                    @Override
                    protected void onCustomNext(ResMoney resOods) {
                        if (resOods.code == 0) {
                            mFragment.moneychange(resOods);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }
}